var columns = [{
    checkbox: true
},
{
    field: "id",
    title: "id",
    visible: false
},
{
    field: "name",
    title: "角色名称"
},
{
    field: "description",
    title: "说明"
},
{
    field: "status",
    title: "状态",
    formatter: function(value, row, index) {
        if (value == 1) {
            return '删除';
        } else {
            return '正常';
        }
    }
},
{
    field: "createTime",
    title: "创建时间",
    formatter: function(value, row, index) {
        return isEmpty(value) ? null: formatDate(new Date(value), "yyyy-MM-dd hh:mm:ss");
    }
},
{
    field: "updateTime",
    title: "更新时间",
    formatter: function(value, row, index) {
        return isEmpty(value) ? null: formatDate(new Date(value), "yyyy-MM-dd hh:mm:ss");
    }
}];

function queryParams(params) {
    var param = {
        pageNumber: params.pageNumber,
        pageSize: params.pageSize,
        keyword: $('.search input').val()
    };
    return param;
}

//通过table id获取需要初始化的table
var role_table = $('#role_table');

//初始化的table
initTable(role_table, $('#role_toolbar'), 'role/list', columns, queryParams, 'zh-CN', true);

//给搜索框添加提示
$('.search input').attr("placeholder", "搜索角色名称/标识");

// 删除按钮
function btnDel() {
    var ids = getSelections(role_table, 'id');
    if (ids.length == 0) {
        layer.msg("请选择要删除的记录", {
            icon: 0
        });
    } else {
        layer.confirm('确定删除所选记录？', {
            icon: 3
        },
        function(index) {
            $.post('role/deleteList', {
                "json": JSON.stringify(ids)
            },
            function(json) {
                if (json.status) {
                	var rows = role_table.bootstrapTable('getData');
                	var options = role_table.bootstrapTable('getOptions');
                	//console.log(options);
                	if(rows!=null && rows.length==1){
                		options.pageNumber = 1
                	}
                	role_table.bootstrapTable('refresh');
                }
                layer.msg(json.message);
            })
            layer.close(index);
        });
    }
}
/*
function btnDel() {
    var ids = getSelections(role_table, 'id');
    if (ids.length == 0) {
        layer.msg("请选择要删除的记录", {
            icon: 0
        });
    } else {
        layer.confirm('确定删除所选记录？', {
            icon: 3
        },
        function(index) {
            $.post('role/deleteList', {
                "json": JSON.stringify(ids)
            },
            function(json) {
                if (json.status) {
                    role_table.bootstrapTable('refresh');
                }
                layer.msg(json.message);
            })
            layer.close(index);
        });
    }
}

*/


// 修改按钮
function btnEdit() {
    var ids = getSelections(role_table, 'id');
    if (ids.length == 1) {
        loadPage('role/' + ids.toString() + '/select');
    } else {
        layer.msg("你没有选择行或选择了多行数据", {
            icon: 0
        });
    }
}

// 权限分配按钮
function permission() {
    var ids = getSelections(role_table, 'id');
    if (ids.length == 1) {
        loadPage('role/' + ids.toString() + '/permission');
    } else {
        layer.msg("你没有选择行或选择了多行数据", {
            icon: 0
        });
    }
}